package com.fulu.game.bi.controller.auth;

import com.fulu.game.bi.common.controller.BaseController;
import com.fulu.game.bi.entity.po.auth.BiUser;
import com.fulu.game.bi.entity.vo.Result;
import com.fulu.game.bi.entity.vo.auth.user.UserQueryVO;
import com.fulu.game.bi.entity.vo.auth.user.UserSaveVO;
import com.fulu.game.bi.redis.service.auth.BiUserService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户管理
 */
@RestController
@RequestMapping("/api/v1/admin")
@Slf4j
public class UserController extends BaseController {

    @Autowired
    private BiUserService biUserService;

    /**
     * 列表查询
     * @param vo 查询条件
     * @return
     */
    @PostMapping("/list")
    public Result<Page<BiUser>> list(UserQueryVO vo) {
        PageInfo<BiUser> page = biUserService.list(vo);

        return Result.success().data(page).msg("查询成功");
    }

    /**
     * 保存用户
     * @param vo 用户信息
     * @return
     */
    @PostMapping("/save")
    public Result<BiUser> save(UserSaveVO vo) {
        BiUser user = biUserService.save(vo);

        return Result.success().data(user).msg("保存成功");
    }

    /**
     * 删除用户
     */
    @PostMapping("/del")
    public Result delete(@RequestParam("adminId") Integer adminId) {
        biUserService.deleteById(adminId);

        return Result.success().msg("删除成功");
    }

    @PostMapping("/query")
    public Result<BiUser> query(@RequestParam("adminId") Integer adminId) {
        BiUser user = biUserService.findById(adminId);

        return Result.success().data(user).msg("查询成功");
    }


}
